package com.snail.jj.androiddemos.components;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;

import com.snail.jj.androiddemos.R;
import com.snail.jj.androiddemos.bases.BaseActivity;
import com.snail.jj.androiddemos.beans.Dog;
import com.snail.jj.androiddemos.beans.Person;

/**
 * Created by snail on 2017/5/8.
 */

public class TestActivity extends BaseActivity {

    private final static String TAG = "TestActivity";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_testactivity);
        initView();
        setResult(5);
    }

    /**
     * 简单传值接收
     */
    public void getJDData() {
        Intent intent = getIntent();
        String name = intent.getStringExtra("name");
        Log.i(TAG,name);
    }

    /**
     * Bundle传递数据包
     */
    public void getBundleData() {
        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        Log.i(TAG,bundle.getString("name"));
    }

    /**
     * 自定义对象传值 实现Serializable接口的对象
     */
    public void getBeanData() {
        Intent intent = getIntent();
        Person person = (Person) intent.getSerializableExtra("Person");
        Log.i(TAG,person.getName());
    }

    /**
     * 自定义对象传值 实现Parcelable接口的对象
     */
    public void getBeanData1() {
        Intent intent = getIntent();
        Dog dog = intent.getParcelableExtra("Dog");
        Log.i(TAG,dog.getName());
    }

    public void initView() {
        setTitleBarTitle("测试传值");
    }
}
